#include"Date.h"
Date Date::print(const Date& d) {

	if (d._month < 10 && d._day < 10)
		cout << d._year << "-" << 0 << d._month << "-" << 0 << d._day << endl;
	else if (d._month >= 10 && d._day < 10)
		cout << d._year << "-" << d._month << "-" << 0 << d._day << endl;
	else if (d._month < 10 && d._day >= 10)
		cout << d._year << "-" << 0 << d._month << "-" << d._day << endl;
	else
		cout << d._year << "-" << d._month << "-" << d._day << endl;
	return d;
}
bool Date::operator<(const Date& date1)
{
	if (_year < date1._year)
	{
		return true;
	}
	else if (_year == date1._year)
	{
		if (_month < date1._month)
		{
			return true;
		}
		else if (_month == date1._month)
		{
			if (_day < date1._day)
			{
				return true;
			}
		}
	}
	return false;
}
bool Date::operator>(const Date& date1)
{
	return !(*this < date1 || *this == date1);
}
bool Date::operator==(const Date& date1)
{
	return(_year == date1._year) && (_month == date1._month) && (_day == date1._day);
}
bool Date::operator<=(const Date& date1)
{
	return *this < date1 || *this == date1;
}
bool Date::operator>=(const Date& date1)
{
	return *this > date1 || *this == date1;
}
bool Date::operator!=(const Date& date1)
{
	return !(*this == date1);
}
int  Date::operator-(const Date& date1)
{
	int gap = 0;
	Date min = (*this);
	Date max = date1;
	int flag = -1;
	if (min > max)
	{
		min = date1;
		max = (*this);
		int flag = 1;
	}
	while (min < max)
	{
		min.operator++();
		gap++;
	}
	return gap * flag;
}
Date Date::operator+(int day)
{
	if (day < 0)
	{
		Date d2 = (*this).operator-(-day);
		return d2;
	}
	Date d1 = (*this);
	d1._day += day;
	while (d1._day > GetDaycount(d1._year, d1._month))
	{
		d1._day -= GetDaycount(d1._year, d1._month);
		if (d1._month == 12)
		{
			d1._year++;
			d1._month = 1;
		}
		else
		{
			d1._month++;
		}
	}
	return d1;
}
Date Date::operator-(int day)
{
	if (day < 0)
	{
		Date d2 = (*this).operator+(-day);
		return d2;
	}
	Date d1 = (*this);
	d1._day -= day;
	while (d1._day < 0)
	{
		if (d1._month == 1)
		{
			d1._month = 12;
			d1._year--;
		}
		else
		{
			d1._month--;
		}
		d1._day += GetDaycount(d1._year, d1._month);
	}
	return d1;
}
Date Date::operator++(int)
{
	Date d1 = (*this).operator+(1);
	return d1;
}
Date& Date::operator++()
{
	(*this) = (*this).operator+(1);
	return *this;
}
